/**    
 * 文件名：Ex1ComputeHistogram.java    
 *    
 * 版本信息：    
 * 日期：2014年3月10日    
 * xyj 足下 xyj 2014     
 * 版权所有    
 *    
 */
package opencvtest.chapter04;

import static com.googlecode.javacv.cpp.opencv_highgui.CV_LOAD_IMAGE_GRAYSCALE;
import static opencvtest.OpenCVUtils.loadAndShowOrExit;

import java.io.File;

import com.googlecode.javacv.cpp.opencv_core.IplImage;

/**
 * The first example for section "Computing the image histogram" in Chapter 4,
 * page 91. Computes histogram using utility class
 * [[opencv2_cookbook.chapter04.Histogram1D]] and prints values to the screen.
 */
public class Ex1ComputeHistogram {

    public static void main(String[] args) {

        // Load image as a gray scale since we will be calculating histogram of
        // an image with a single channel
        IplImage src = loadAndShowOrExit(new File("data/group.jpg"), CV_LOAD_IMAGE_GRAYSCALE);

        // Calculate histogram
        Histogram1D h = new Histogram1D();
        float[] histogram = h.getHistogramAsArray(src);

        // Print histogram values, the Scala way
        for (float hist : histogram) {

        }

        // Validate histogram computations
        int numberOfPixels = src.width() * src.height();
        System.out.println("Number of pixels  :" + numberOfPixels);
        // int sumOfHistogramBins = round(histogram);
    }
}
